// const Express = require('express')   Commonjs
import Express from 'express'
import { UserRouter } from './router/user.js';
import { captchaRouter } from './router/captcha.js';
import cookieParser from 'cookie-parser';
import Session from 'express-session';
import "./Model/initDB.js"
import { errmiddleware } from "./Middleware/index.js"

import { authenticateToken } from "./token/intercept.js"
import { UploadRouter } from './router/upload.js';
import { typeRouter } from './router/type.js';
import { articlesRouter } from './router/articles.js';
import { commentRouter } from './router/comment.js';
const server = Express();

server.use(Express.json());

server.use(cookieParser())
server.use(Express.static("./static/avatar"))
server.use(Express.static("./static/upload"))
server.use(Session({
        secret: 'buka',
        saveUninitialized: true,
        resave: true
    }))
server.use(authenticateToken)
// 完成路由的封装
server.use('/api/user', UserRouter)
server.use('/api/captcha', captchaRouter)
server.use('/api/upload',UploadRouter)
server.use('/api/type',typeRouter)
server.use("/api/issue",articlesRouter)
server.use("/api/comment",commentRouter)


server.use(errmiddleware);
server.listen(8090, () => {
    console.log('服务器运行在 8090端口')
});